#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
        pid_t pid = fork();
        if(pid == 0){
                printf("I am child,will die!\n");
                sleep(30);
                //return 101;
                exit(102);
        }else if(pid > 0){
                printf("I am parent, wait for child die!\n");
                int status;

                pid_t wpid = wait(&status);
                printf("wait ok,wpid=%d,pid=%d\n",wpid,pid);
                if(WIFEXITED(status)){
                        printf("child exit with %d\n", WEXITSTATUS(status));
                }
                if(WIFSIGNALED(status)){
                        printf("child killed by %d\n", WTERMSIG(status));
                }

                while (1){
                        sleep(1);
                }
        }
        
        return 0;
}
